﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using CapPhatTB.DAL;
using System.Data;
using DanhmucThietbi;
namespace CapPhatTB.BLL
{
   public class CapPhat_TB
    {
       private SqlConnection conn = new SqlConnection();
       public CapPhat_TB()
        {
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString;
        }
       public DataTable Load_DSTB()
       {
           StringBuilder strSQL = new StringBuilder("");
           strSQL.Append("select DEV_THIETBI.ma_tb, DEV_THIETBI.ten_tb,DEV_PHANLOAI.ten_ploai, ");
           strSQL.Append("DEV_THIETBI.thongtin_tb from dbo.DEV_THIETBI, DEV_PHANLOAI ");
           strSQL.Append("where DEV_THIETBI.is_lkien = 0 and DEV_THIETBI.is_delete = 0 ");
           strSQL.Append("and ma_donvi is null and DEV_THIETBI.ma_ploai = DEV_PHANLOAI.ma_ploai");
           SqlCommand sqlCmd = new SqlCommand();
           sqlCmd.Connection = conn;
           sqlCmd.CommandText = strSQL.ToString();
           sqlCmd.CommandType = System.Data.CommandType.Text;
           sqlCmd.Connection.Open();
           sqlCmd.ExecuteNonQuery();
           sqlCmd.Connection.Close();
           SqlDataAdapter DA = new SqlDataAdapter();
           DA.SelectCommand = sqlCmd;
           DataTable dt = new DataTable();
           DA.Fill(dt);
           sqlCmd.Connection.Close();
           return dt;
       }
       public void Add_Item_CapPhat(CapPhatInfo objCapPhat)
       {
           StringBuilder strSQL = new StringBuilder("");
           strSQL.Append("insert into DEV_CAPPHAT(NV_CAP,MA_TB,MA_DV,NV_SUDUNG,NGAY_CAP) ");
           strSQL.Append("values (@NV_CAP, @MA_TB, @MA_DV, @NV_SUDUNG, @NGAY_CAP)");
           SqlCommand sqlCmd = new SqlCommand();
           sqlCmd.Parameters.Add(new SqlParameter("@NV_CAP", objCapPhat.NV_CAP));
           sqlCmd.Parameters.Add(new SqlParameter("@MA_TB", objCapPhat.MA_TB));
           sqlCmd.Parameters.Add(new SqlParameter("@MA_DV",objCapPhat.MA_DV));
           sqlCmd.Parameters.Add(new SqlParameter("@NV_SUDUNG", objCapPhat.NV_SUDUNG));
           sqlCmd.Parameters.Add(new SqlParameter("@NGAY_CAP", objCapPhat.NGAY_CAP));
           sqlCmd.Connection = conn;
           sqlCmd.CommandText = strSQL.ToString();
           sqlCmd.CommandType = System.Data.CommandType.Text;
           sqlCmd.Connection.Open();
           sqlCmd.ExecuteNonQuery();
           sqlCmd.Connection.Close();
       }
       public void Update_ThietBi(ThietBiInfo objTB)
       {
           StringBuilder strSQL = new StringBuilder("");
           strSQL.Append("update DEV_THIETBI set MA_DONVI = @MA_DONVI ");
           strSQL.Append("where MA_TB = @MA_TB");
           SqlCommand sqlCmd = new SqlCommand();
           sqlCmd.Parameters.Add(new SqlParameter("@MA_DONVI", objTB.MA_DONVI));
           sqlCmd.Parameters.Add(new SqlParameter("@MA_TB", objTB.MA_TB));
           sqlCmd.Connection = conn;
           sqlCmd.CommandText = strSQL.ToString();
           sqlCmd.CommandType = System.Data.CommandType.Text;
           sqlCmd.Connection.Open();
           sqlCmd.ExecuteNonQuery();
           sqlCmd.Connection.Close();
       }
    }
}
